package com.lwbldy.common.tools;

import java.util.ArrayList;
import java.util.List;

public class StringUtils {

    /**
     * id 数组列表转换成List
     * @param ids
     * @return
     */
    public static List<Integer> StringToIntArr(String[] ids){
        if(ids == null || ids.length == 0){
            return new ArrayList<>();
        }
        List<Integer> idsArr = new ArrayList<>();
        for(String s : ids){
            try {
                idsArr.add(Integer.parseInt(s));
            }catch (Exception e){
                e.printStackTrace();
            }
        }
        return idsArr;
    }

    public static List<Long> StringToLongArr(String[] ids){
        if(ids == null || ids.length == 0){
            return new ArrayList<>();
        }
        List<Long> idsArr = new ArrayList<>();
        for(String s : ids){
            try {
                idsArr.add(Long.parseLong(s));
            }catch (Exception e){
                e.printStackTrace();
            }
        }
        return idsArr;
    }


    public static Long[] StringIdsToArr(String ids){
        String[] idsArr = ids.split(",");
        if(idsArr!=null && idsArr.length!=0){
            Long[] idsLong = new Long[idsArr.length];
            for(int i = 0;i<idsArr.length;i++){
                Long id = Long.parseLong(idsArr[i]);
                idsLong[i] = id;
            }
            return idsLong;
        }else{
            return null;
        }
    }

    public static Integer[] StringIdsToArrInt(String ids){
        String[] idsArr = ids.split(",");
        if(idsArr!=null && idsArr.length!=0){
            Integer[] idsLong = new Integer[idsArr.length];
            for(int i = 0;i<idsArr.length;i++){
                Integer id = Integer.parseInt(idsArr[i]);
                idsLong[i] = id;
            }
            return idsLong;
        }else{
            return null;
        }
    }

}
